<?php
/*
Plugin Name: eSfaturi.ro - Socials plugin
Plugin URI: 
Description: Displays twitter, facebook and other social links
Version: 1.0.0
Author: Sergiu Bologa
Author URI: 
License: GPL2
*/

// Start class
class esf_social_widget extends WP_Widget {
	
	// Constructor
	function esf_social_widget() {
		$widget_ops = array( 'classname' => 'esf-social-widget', 'description' => 'Displays twitter, facebook and other social links' );
		
		// Widget Settings
		$control_ops = array( 'id_base' => 'esf_social_widget' ); // Widget Control Settings
		$this->WP_Widget( 'esf_social_widget', 'Socials widget', $widget_ops, $control_ops ); // Create the widget
	}

	// Extract Args
	function widget($args, $instance) {
		extract( $args );
		$title = apply_filters('widget_title', $instance['title']); // the widget title
		//$facebookUrl = $instance['facebookUrl'];
		//$twitterUrl = $instance['twitterUrl'];
		//$gplusUrl = $instance['gplusUrl'];
		
		// Before widget
		echo $before_widget;
		
		// Title of widget
		if ( $title ) { echo $before_title . $title . $after_title; }

		// Widget output
		$dir = get_bloginfo ( 'template_directory' );
		echo '<a href="'. get_option("esf_facebook_url") .'" target="_blank" title="eSfaturi.ro pe Facebook"><img src="'. $dir .'/styles/images/facebook.png" alt="Facebook" /></a>
		<a href="'. get_option("esf_twitter_url") .'" target="_blank" title="eSfaturi.ro pe Twitter"><img src="'. $dir .'/styles/images/twitter.png" alt="Twitter" /></a>
		<a href="'. get_option("esf_google_plus_url") .'" target="_blank" title="eSfaturi.ro pe Google Plus"><img src="'. $dir .'/styles/images/google-plus-64x64.png" alt="Google Plus" /></a>
		<a href="'. get_bloginfo('rss2_url') .'" target="_blank" title="Feed-ul eSfaturi.ro"><img src="'. $dir .'/styles/images/rss.png" alt="RSS Feed" /></a>';

		// After widget
		echo $after_widget;
	}
	
	// Update Settings
	function update($new_instance, $old_instance) {
 		$instance['title'] = strip_tags($new_instance['title']);
		//$instance['facebookUrl'] = $new_instance['facebookUrl'];
		//$instance['twitterUrl'] = $new_instance['twitterUrl'];
		//$instance['gplusUrl'] = $new_instance['gplusUrl'];
 		return $instance;
 	}
	
	// Widget Control Panel
	function form($instance) {
 		$defaults = array( 'title' => 'Social', 'facebookUrl' => '#', 'twitterUrl' => '#', 'gplusUrl' => '#' );
 		$instance = wp_parse_args( (array) $instance, $defaults ); ?>

 		<p>
			<label for="<?php echo $this->get_field_id('title'); ?>">Title:</label>
 			<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $instance['title']; ?>" />
 		</p>
		
		<!--p>
			<label for="<?php echo $this->get_field_id('facebookUrl'); ?>">Facebook URL:</label>
 			<input class="widefat" id="<?php echo $this->get_field_id('facebookUrl'); ?>" name="<?php echo $this->get_field_name('facebookUrl'); ?>" type="text" value="<?php echo $instance['facebookUrl']; ?>" />
 		</p>
 		
		<p>
			<label for="<?php echo $this->get_field_id('twitterUrl'); ?>">Twitter URL:</label>
 			<input class="widefat" id="<?php echo $this->get_field_id('twitterUrl'); ?>" name="<?php echo $this->get_field_name('twitterUrl'); ?>" type="text" value="<?php echo $instance['twitterUrl']; ?>" />
 		</p>
		
		<p>
			<label for="<?php echo $this->get_field_id('gplusUrl'); ?>">Google Plus URL:</label>
 			<input class="widefat" id="<?php echo $this->get_field_id('gplusUrl'); ?>" name="<?php echo $this->get_field_name('gplusUrl'); ?>" type="text" value="<?php echo $instance['gplusUrl']; ?>" />
 		</p-->
		
        <?php 
	}
}

// End class csc-social-widget
add_action('widgets_init', create_function('', 'return register_widget("esf_social_widget");'));
?>